package cn.iocoder.yudao.module.crossborder.inventory.api;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.crossborder.inventory.api.dto.InventoryDTO;
import cn.iocoder.yudao.module.crossborder.inventory.api.dto.WarehouseDTO;
import cn.iocoder.yudao.module.crossborder.inventory.service.InventoryService;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * 库存管理 API 接口实现类
 *
 * @author LHL
 */
@RestController // 提供 RESTful API 接口，给 Feign 调用
@Validated
public class InventoryApiImpl implements InventoryApi {

    @Resource
    private InventoryService inventoryService;

    @Override
    public CommonResult<InventoryDTO> getInventory(Long id) {
        InventoryDTO inventory = inventoryService.getInventory(id);
        return success(inventory);
    }

    @Override
    public CommonResult<List<InventoryDTO>> getInventoryList(List<Long> ids) {
        List<InventoryDTO> inventories = inventoryService.getInventoryList(ids);
        return success(inventories);
    }

    @Override
    public CommonResult<Long> createInventory(InventoryDTO inventory) {
        Long id = inventoryService.createInventory(inventory);
        return success(id);
    }

    @Override
    public CommonResult<Boolean> checkStock(Long productId, Long warehouseId, Integer quantity) {
        Boolean result = inventoryService.checkStock(productId, warehouseId, quantity);
        return success(result);
    }

    @Override
    public CommonResult<Boolean> reserveStock(Long productId, Long warehouseId, Integer quantity) {
        Boolean result = inventoryService.reserveStock(productId, warehouseId, quantity);
        return success(result);
    }

    @Override
    public CommonResult<Boolean> releaseStock(Long productId, Long warehouseId, Integer quantity) {
        Boolean result = inventoryService.releaseStock(productId, warehouseId, quantity);
        return success(result);
    }

    @Override
    public CommonResult<WarehouseDTO> getWarehouse(Long id) {
        WarehouseDTO warehouse = inventoryService.getWarehouse(id);
        return success(warehouse);
    }

}
